package com.sicurezza.model;

import java.util.ArrayList;

import com.progettoSicurezza.nfcrypto.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PersonAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<Person> personList;

	public PersonAdapter(Context context, ArrayList<Person> personList) {
		super();
		this.mContext = context;
		this.personList = personList;
	}

	@Override
	public int getCount() {
		return personList.size();
	}

	@Override
	public Object getItem(int position) {
		return personList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Person person = personList.get(position);
		
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			inflater.inflate(R.layout.element_list, null);
		}
		
		TextView contactDisplayNameView = (TextView) convertView.findViewById(R.id.textViewContactDisplayName);
		contactDisplayNameView.setText(person.getDisplayName());
		
		TextView contactPhoneNumberView = (TextView) convertView.findViewById(R.id.textViewContactPhoneNumber);
		contactPhoneNumberView.setText(person.getPhoneNumber());
		
		TextView contactEmailAddress = (TextView) convertView.findViewById(R.id.textViewContactEmailAddress);
		contactEmailAddress.setText(person.getEmailAddress());
		
		return convertView;
	}

}
